package org.tloss.web.editor.database.editors;

import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.tloss.web.editor.database.editors.jdbc.Schema;
import org.tloss.web.editor.utils.Constants;

public class SchemaLableProvider extends LabelProvider implements
		ITableLabelProvider {

	@Override
	public Image getColumnImage(Object arg0, int arg1) {
		if (arg0 instanceof Schema) {
			Schema config = (Schema) arg0;

			switch (arg1) {
			case 0:
				return config.getSchemaName() != null ? Constants.DATABASE_IMAGE
						: null;
			case 1:
				return config.getCatalogName() != null ? (config
						.getSchemaName() == null ? Constants.DATABASE_IMAGE
						: null) : null;
			}
		}

		return null;

	}

	@Override
	public String getColumnText(Object arg0, int arg1) {
		if (arg0 instanceof Schema) {
			Schema config = (Schema) arg0;
			switch (arg1) {
			case 0:
				return config.getSchemaName() != null ? config.getSchemaName()
						: config.getCatalogName() == null ? "Please choose"
								: "";
			case 1:
				return config.getCatalogName() != null ? config
						.getCatalogName() : "";
			}
		}
		return "";
	}
}
